Beginning Swift Programming by Wei-Meng Lee
Author:Wei-Meng Lee [Lee, Wei-Meng]
Language: eng
Format: azw3, pdf
ISBN: 9781119009320
Publisher: Wiley
Published: 2014-12-03T16:00:00+00:00
Where Clause
You can use the Switch statement together with a where clause to check for additional conditions. For example, if you wanted to check if the scores for both subjects are greater than 80, you could write the following case:
//---(math, science)--- var scores = (90,90) switch scores { case (0,0): println("This is not good!") case (100,100): println("Perfect score!") case let (math, science) where math > 80 && science > 80: println("Well done!") case (50...100, let science): println("Math pass!") if science<50 { println("But Science fail!") } else { println("And Science also pass!") } case (let math, 50...100): println("Science pass!") if math<50 { println("But Math fail!") } else { println("And Math also pass!") } case let (math, science): println("Math is \(math) and Science is \(science)") }
In the preceding code snippet, the third case assigns the scores of the math and science subjects to the temporary variables math and science, respectively, and uses the where clause to specify the condition that the scores for both math and science must be greater than 80. The preceding example will output the following statement:
Well done!
If you want to match the case where the math score is greater than the science score, you can specify the following where clause:
case let (math, science) where math > science: println("You have done well for Math!")
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6394)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6229)
Kotlin in Action by Dmitry Jemerov(4871)
Odoo 15 Development Essentials by Daniel Reis(2696)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(2587)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2417)
Learning Angular - Second Edition by Christoffer Noring(2241)
Pride and Prejudice by Jane Austen(2206)
Mobile Forensics Cookbook by Igor Mikhaylov(1900)
Computers For Seniors For Dummies by Nancy C. Muir(1867)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1751)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1687)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1677)
1936941139 (N) by Bob Rosenthal(1602)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1597)
Hands-On Internet of Things with MQTT by Tim Pulver(1578)
Android App Development by Franceschi Hervé J.;(1574)
Ember.js in Action by Joachim Haagen Skeie(1552)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1533)